package com.qidianit.mes.sys.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qidianit.mes.pojo.Supplier;
import com.qidianit.mes.sys.mapper.SupplierMapper;
import com.qidianit.mes.sys.service.SupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description:
 * @Author: shanzhe
 * @Date: 2025/9/16 - 19:58
 */
@Service
public class SupplierServiceImpl implements SupplierService {
    @Autowired
    private SupplierMapper supplierMapper;

    @Override
    public PageInfo<Supplier> selectSuppliersByConditionsWithPaging(String code, String name, Integer status, Integer pageNum, Integer size) {

        PageHelper.startPage(pageNum,size);
        List<Supplier> supplierList = supplierMapper.selectSuppliersByConditionsWithPaging(code,name,status,pageNum,size);
        PageInfo<Supplier> supplierPageInfo = new PageInfo<>(supplierList);
        return supplierPageInfo;
    }

    @Override
    public Supplier selectSupplierByCode(String code) {
        return supplierMapper.selectSupplierByCode(code);
    }

    @Override
    public int addSupplier(Supplier supplier) {
        int result = supplierMapper.addSupplier(supplier);
        return result;
    }

    @Override
    public int updateSupplierById(Supplier supplier) {
        int result = supplierMapper.updateSupplierById(supplier);
        return result;
    }

    @Override
    public int deleteSupplierById(Integer id) {
        int result = supplierMapper.deleteSupplierById(id);
        return result;
    }

    @Override
    public int deleteSupplierByIds(List<Integer> ids) {
        Integer sum = 0;
        for (Integer id : ids) {
            sum += deleteSupplierById(id);
        }
        if (sum == ids.size()) {
            return 1;
        }else if (sum > 0) {
            return -1;
        }else  {
            return 0;
        }
    }
}
